home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / BTCLASS.ZIP / EXAMPLE@.EXE / EXAMPLES.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-07  |  4.2 KB  |  135 lines

  1. /*//////////////////////////////////////////////////////////////////////////
  2. ///            ___                                                       ///
  3. ///          /_____\                                                     ///
  4. ///         |       |                 Copyright (c) 1991                 ///
  5. ///         |   R   |                                                    ///
  6. ///     ----|_______|----                     by                         ///
  7. ///   /------/ | | \------\                                              ///
  8. ///  |       | | | |       |      --  Object Resource Group  --          ///
  9. ///  |   O   | | | |   G   |                                             ///
  10. ///  |       |/   \|       |          4323 Brown Suite 249               ///
  11. ///   -------       -------            Dallas,  TX  75219                ///
  12. ///   Object Resource Group                                              ///
  13. ///                                      (214) 528-2745                  ///
  14. ///                                                                      ///
  15. ///                                    All Rights Reserved.              ///
  16. ///                                                                      ///
  17. //////////////////////////////////////////////////////////////////////////*/
  18.  
  19. // definitions for classes used as examples
  20. #if !defined(EXAMPLES_HPP)
  21. #define EXAMPLES_HPP
  22.  
  23. #include <string.h>
  24. #include "btdset.hpp"
  25.  
  26. // PersonDB is a "kind-of" BT_DataSet (or btrieve file)
  27. // It adds the methods to dump its data
  28. // It adds no new attributes
  29. class PersonDB : public BT_DataSet
  30.    {
  31.    public:
  32.  
  33.    PersonDB(char *name) : BT_DataSet(name) {};
  34.    int Dump();        // dump in key 0 order
  35.    int ColorDump();    // create a supplemental key (based on color) and
  36.             // dump in that order
  37.    };
  38.  
  39. // ColorDB is a "kind-of" BT_DataSet (or btrieve file)
  40. // It adds the methods to dump its data
  41. // It adds no new attributes
  42. class ColorDB : public BT_DataSet
  43.    {
  44.    public:
  45.  
  46.    ColorDB(char *name) : BT_DataSet(name) {};
  47.    int Dump();                    //Dumps in color order
  48.    int DumpFromHighestCount();    //Dumps in color order from highest count
  49.    };
  50.  
  51. struct PersonData
  52.    {
  53.    char name[36];            // person's name
  54.    char colorPreference[26];    // user defined color shade
  55.    };
  56.  
  57. class Person
  58.    {
  59.    PersonData data;
  60.    PersonDB *personDB;        // connect to person's file
  61.  
  62.    public:
  63.  
  64.    // default constructor  - connects object to file
  65.    Person(PersonDB *_personDB) : personDB(_personDB)
  66.         {
  67.         memset(data.name, '\0', 36);
  68.         memset(data.colorPreference, '\0', 26);
  69.         }
  70.  
  71.    // specialized constructor to set the name and do a lookup for the record
  72.    Person(char *_name, PersonDB *personDB);
  73.  
  74.    // destructor - does nothing
  75.    ~Person() {};
  76.  
  77.    // set the object's attributes
  78.    void SetName(char *_name) { strncpy(data.name, _name, 35); }
  79.    void SetColorPreference(char *_color) { strncpy(data.colorPreference,
  80.                            _color, 25); }
  81.  
  82.   // get the object's attributes
  83.    char *ColorPreference() { return data.colorPreference; }
  84.    char *Name() { return data.name; }
  85.  
  86.    // file operations
  87.    int Add();
  88.    int GetRec();
  89.    int Status() { return personDB->Status(); }
  90.    };
  91.  
  92. struct ColorData
  93.    {
  94.    char shade[26];    // user defined color
  95.    int prefCount;    // number of people with that preference
  96.    };
  97.  
  98. class Color
  99.    {
  100.    ColorData data;
  101.    ColorDB *colorDB;        // connect to color's file
  102.  
  103.    public:
  104.  
  105.    // default constructor to link object to file
  106.    Color(ColorDB *_colorDB) : colorDB(_colorDB)
  107.         {
  108.         data.prefCount = 0;
  109.         memset(data.shade, '\0', 26);
  110.         }
  111.  
  112.    // specialized constructor to set the shade and do a lookup for the record
  113.    Color(char *_name, ColorDB *colorDB);
  114.  
  115.    // destructor - does nothing
  116.    ~Color() {};
  117.  
  118.    // set the object's attributes
  119.    void SetShade(char *_color) { strncpy(data.shade, _color, 25); }
  120.    void SetPrefCount(int _count) { data.prefCount = _count; }
  121.    void IncPrefCount() { data.prefCount++; }
  122.  
  123.    // get the object's attributes
  124.    char *Shade() { return data.shade; }
  125.    int PreferenceCount() { return data.prefCount; }
  126.  
  127.    // file operations
  128.    int Add();
  129.    int Update();
  130.    int GetRec();
  131.    int Status() { return colorDB->Status(); }
  132.    };
  133.  
  134. #endif
  135.